package com.project.collectAPI.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.collectAPI.dao.BackupsupermarketoldtaskDao;
import com.project.collectAPI.entity.Backupsupermarketoldtask;
import com.project.collectAPI.service.BackupsupermarketoldtaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * (Backupsupermarketoldtask)表服务实现类
 *
 * @author makejava
 * @since 2024-02-26 11:56:00
 */
@Service("backupsupermarketoldtaskService")
public class BackupsupermarketoldtaskServiceImpl extends ServiceImpl<BackupsupermarketoldtaskDao, Backupsupermarketoldtask> implements BackupsupermarketoldtaskService {

    @Autowired
    BackupsupermarketoldtaskDao backupsupermarketoldtaskDao;


    @Override
    public void setTask(int taskId,int firstArrIndex, int secondArrIndex,String TaskName,String secondarrays) {
        Backupsupermarketoldtask taskData=backupsupermarketoldtaskDao.selectOne(new QueryWrapper<Backupsupermarketoldtask>().eq("id",taskId));
        if(taskData==null){ //为空才插入新用户
            Backupsupermarketoldtask newData=new Backupsupermarketoldtask();
            newData.setTaskfirst(0);
            newData.setTasksecond(0);
            newData.setTaskname(TaskName);
            newData.setSecondarrays(secondarrays);
            backupsupermarketoldtaskDao.insert(newData);
        }else{
            taskData.setId(taskId);
            taskData.setTaskfirst(firstArrIndex);
            taskData.setTasksecond(secondArrIndex);
            taskData.setTaskname(TaskName);
            taskData.setSecondarrays(secondarrays);
            //System.out.println("更新==》"+taskData);
            backupsupermarketoldtaskDao.updateById(taskData);
        }
    }

    @Override
    public void updateStatusById(int taskId, String status) {
        Backupsupermarketoldtask taskData=new Backupsupermarketoldtask();
        taskData.setId(taskId);
        taskData.setStatus(status);
        backupsupermarketoldtaskDao.updateById(taskData);
    }

    @Override
    public String getStatusById(int taskId) {
        Backupsupermarketoldtask taskData=backupsupermarketoldtaskDao.selectOne(new QueryWrapper<Backupsupermarketoldtask>().eq("id",taskId));
        return taskData.getStatus();
    }

    @Override
    public void updateSecondArrsById(int taskId, String secondarrays) {
        Backupsupermarketoldtask taskData=new Backupsupermarketoldtask();
        taskData.setId(taskId);
        taskData.setSecondarrays(secondarrays);
        backupsupermarketoldtaskDao.updateById(taskData);
    }

    @Override
    public String getSecondArrs(int taskId) {
        Backupsupermarketoldtask taskData=backupsupermarketoldtaskDao.selectOne(new QueryWrapper<Backupsupermarketoldtask>().eq("id",taskId));
        return taskData.getSecondarrays();
    }

    @Override
    public void updateDataFile(int taskId, Backupsupermarketoldtask backupSupermarketOldTask) {
        backupsupermarketoldtaskDao.insert(backupSupermarketOldTask);
    }
}

